package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.StrategyDetail;
import cn.wolfcode.luowowo.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo.article.service.IStrategyDetailService;
import cn.wolfcode.luowowo.article.service.IStrategyThemeService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.query.StrategyQueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyDetail")
public class StrategyDetailController {
    @Reference
    private IStrategyDetailService strategyDetailService;
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo")StrategyQueryObject qo, Model model){
        PageInfo pageInfo = strategyDetailService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "strategyDetail/list";
    }

    @Reference
    private IStrategyCatalogService strategyCatalogService;
    @Reference
    private IStrategyThemeService strategyThemeService;
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if (id != null){
            StrategyDetail detail = strategyDetailService.get(id);
            model.addAttribute("entity",detail);
            model.addAttribute("tags",strategyDetailService.getTag(id));
        }
        model.addAttribute("catalogs",strategyCatalogService.list());
        model.addAttribute("themes", strategyThemeService.list());

        return "strategyDetail/input";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyDetail entity,String tags){
        strategyDetailService.saveOrUpdate(entity,tags);
        return new AjaxResult();
    }
}
